home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: wzjn@ix.netcom.com (KPN )
- Newsgroups: comp.lang.c
- Subject: Re: More Modulus questions
- Date: 21 Feb 1996 18:43:54 GMT
- Organization: Netcom
- Message-ID: <4gfp5a$r8e@cloner2.ix.netcom.com>
- References: <Pine.SOL.3.90.960219171637.21117B-100000@eddie> <4gfnka$ni7@spanky.pls.ov.com>
- NNTP-Posting-Host: ix-frm-ma1-04.ix.netcom.com
- X-NETCOM-Date: Wed Feb 21 10:43:54 AM PST 1996
-
- Good Afternoon,
-
- Recently I asked a question concerning the proper use of the Modulus
- code. Many replied back to me to help clear up m confusion, and many
- replied back to the group to help me. I thank all of you for your time
- and expertise.
-
- As I looked over what had been sent to me, a great deal of the
- responses helped by pointing out that what I was doing was incorrect -
- however, no one really showed me what I should be doing to correct the
- problem! Well, actually, a few examples were to be had, but were so far
- over my knowledge of C thus far, as to be useless to me. Thank you
- anyway to those who sent in.
-
- Here again is my problem: (From æHow to Program CÆ second edition
- Deitel/Dietel - Write a program that reads an integer and determines,
- and prints how many digits in the integer are 7Æs)
-
- #include <stdio.h>
-
- main()
- {
- int number;
- int first, second, third, fourth;
- int integer1, integer2, integer3, integer4;
-
- printf("Enter a four digit number: ");
- scanf("%d", &number);
-
- /*
- Split the four digit number into four seperate integers
- */
-
- first = number / 1000;
- integer1 = number % 1000;
-
- second = integer1 / 100;
- integer2 = integer1 % 100;
-
- third = integer2 / 10;
- integer3 = integer2 % 10;
-
- fourth = integer3 / 1;
- integer4 = integer3 % 1;
-
- /*
- Use modulas to determine if any integers are a 7
- */
-
- if (first % 7)
- printf("First integer was a 7\n");
- else
- printf("Not a 7\n");
-
- if (second % 7)
- printf("second integer was a 7\n");
- else
- printf("Not a 7\n");
-
- if (third % 7)
- printf("third integer was a 7\n");
- else
- printf("Not a 7\n");
-
- if (fourth % 7)
- printf("fourth integer was a 7\n");
- else
- printf("Not a 7\n");
-
-
- Yes, I know that you may have a different style/ would write it
- differently / wouldnÆt do it this way, but thatÆs OK - IÆll learn. All
- that IÆm concerned about right now, is that if I enter the number 7000,
- it tells me that the first digit is not a seven, and all the rest are a
- 7.
-
- Could this be explained to me in verbiage instead of a big complicated
- example using all sorts of code that I do not know yet? I know, that in
- the book IÆm teaching myself from, more than a few examples have IF
- statement conditioned by a Modulus code ... how (in words!!!) does this
- code work?
-
- Thank you for your patience and expertise,
-
- kevin
-
-